<script lang="tsx" setup>
/**
 * 核心渲染器
 */
import {RendererFactory} from "./renderer-factory";
import {RenderType} from "../index.ts";
import {RenderEls} from "../type";

/**
 * 定义props
 */
const props = withDefaults(defineProps<{
  renderType?: RenderType,
  item: RenderEls<any>,
  data?: any,
  reflections?: any[]
}>(), {
  renderType: 'customer'
})

/**
 * 定义emit
 */
const emit = defineEmits<{
  (e: 'setData', item: { key: string, value: any }): void
  (e: string): void
}>()

/**
 * 渲染函数
 */
function render({item}: any) {
  if (item.renderFn) {
    const renderer = RendererFactory.getRenderer();
    return renderer.render(item, props, emit);
  }
  const renderer = RendererFactory.getRenderer(props.renderType);
  return renderer.render(item, props, emit);
}
</script>

<template>
  <component :is="render({item})"/>
</template>